$('.logo').width(_rate*494).height(_rate*95);
$('.p-nan').width(_rate*262).height(_rate*214);
$('.p-nv').width(_rate*262).height(_rate*214);
$('.m-btn').width(_rate*116).height(_rate*65).css({"top":_rate*25, "right":0});
$('.p1-t1').width(_rate*402).height(_rate*70).css({"top":_rate*855, "left":_rate*174});
$('.p1-nan').css({"top":_rate*522, "left":_rate*110});
$('.p1-nv').css({"top":_rate*522, "left":_rate*376});
$('.p2-tou').width(_rate*590).height(_rate*466).css({"top":_rate*375, "left":0});
$('.p2-nan').css({"top":_rate*802, "left":_rate*110});
$('.p2-nv').css({"top":_rate*802, "left":_rate*376});
$('.home-t1').width(_rate*236).height(_rate*136).css({"top":_rate*890, "left":_rate*36});
$('.home-btn').width(_rate*555).height(_rate*256).css({"top":_rate*940, "left":_rate*190});
$('.back').width(_rate*186).height(_rate*86).css({"top":_rate*32, "left":_rate*22});
$('.p2-next').width(_rate*200).height(_rate*100).css({"top":_rate*1070, "left":_rate*506});
$('.p3-t1').width(_rate*720).height(_rate*190).css({"top":_rate*828, "left":0});
$('.p-next').width(_rate*234).height(_rate*92).css({"top":_rate*1074, "left":_rate*492});
$('.p3-next').width(_rate*200).height(_rate*100).css({"top":_rate*1070, "left":_rate*506});
$('.p3-zai').width(_rate*262).height(_rate*214).css({"top":_rate*802, "left":_rate*110});
$('.p3-gong').width(_rate*262).height(_rate*214).css({"top":_rate*802, "left":_rate*376});
$('.gameicobox, .gamebigbox').width(_rate*660).css({"top":_rate*1014, "left":_rate*50});
$('.gamebigbox').height(_rate*140);
$('.game-li').width(_rate*105).height(_rate*136).css({"margin-right":_rate*4});
$('.game-li img').height(_rate*129).css({"top":_rate*6});

$('.p4-k1').width(_rate*45).height(_rate*1206).css({"top":0, "left":0});
$('.p4-k2').width(_rate*44).height(_rate*1206).css({"top":0, "right":0});
$('.p4-k3').width(sWidth).height(_rate*70).css({"top":_rate*1116, "left":0});

$('.p4-ban2').height(_rate*232).css({"top":_rate*972});
$('.p4-txt').width(_rate*688).height(_rate*49).css({"top":_rate*960, "left":0});
$('.gametab').width(_rate*666).css({"top":_rate*974, "left":_rate*50});
$('.gametab2').width(_rate*666).css({"top":_rate*954, "left":_rate*50});
$('.game-tb').width(_rate*126).height(_rate*30).css({"margin-right":_rate*3});
$('.game-cb').width(_rate*126).height(_rate*60).css({"margin-right":_rate*3});
$('#p4-tb5').width(_rate*134).css({"margin-left":_rate*2});
$('.p4-shen').width(_rate*224).height(_rate*86).css({"top":_rate*32, "left":_rate*492});
$('.p5-baocun').width(_rate*488).height(_rate*244).css({"top":_rate*948, "left":_rate*262});

var _p4shenFlag=false;
//合成 生成姿势  
$(".p4-shen").on("click",function () {
    if(_p4shenFlag == true){return;}
    _p4shenFlag=true;
    deleteCtr();
    setTimeout(function () {
        var imgsrc = new Image();
        imgsrc.src = canvas.toDataURL();
        imgsrc.onload = function () {
            var poster = new createjs.Bitmap(imgsrc);
            var OBox = new createjs.Container();
            OBox.addChild(poster);
            OBox.cache(0, 0, 750, 1206);
            var photo = OBox.cacheCanvas.toDataURL();//生成图片地址，1为质量
            $(".p5-tu").attr("src", photo);
            $(".p4").fadeOut();
            $(".p5").fadeIn();
            _p4shenFlag=false;
        }
    }, 500);
});
function _setYF(){
   $(".p4-yifu").html("");
    var _html="";
    for(i=1;i<=6;i++){
       if('nv' == _sex && i == 6){
        _html+='<div class="game-li"></div>';
       }else{
       _html+='<div class="game-li"><img class="game-tu" src="<?php echo $cdnUrl; ?>img/'+_sex+'/'+_chang+'/'+_zishi+'/'+i+'.png" /></div>';
       }
    }
    $(".p4-yifu").html(_html);
    $('.game-li').width(_rate*105).height(_rate*136).css({"margin-right":_rate*4});
    $('.game-li img').height(_rate*129).css({"top":_rate*6});
}
// 选择姿势
$(".p4-zishi").on("click", ".game-li", function () {
    var _id = $(this).index() + 1;
    if('gong' == _chang){
        if(1 == _id){
           _zishi='zhan';
        }else{
           _zishi='zuo';
        }
    }else{
        if(1 == _id){
           _zishi='tang';
        }else{
           _zishi='dun';
        }
    }
    _setYF();
    PerArr[0]=1;
    if(_id > 2){return;}
    $(this).addClass("game_Active").siblings().removeClass("game_Active");
    $(".p4-shen").show();
    AddRen();
});
// 选择衣服
$(".p4-yifu").on("click", ".game-li", function () {
    var _id = $(this).index() + 1;
    if('nv' == _sex && 6 == _id){return;}
    $(this).addClass("game_Active").siblings().removeClass("game_Active");
    PerArr[1]=_id;
    AddYiFu();
    $(".p4-shen").show();
});
// 选择宠物
$(".p4-congwu").on("click", ".game-li", function () {
    var _id = $(this).index() + 1;
    $(this).addClass("game_Active").siblings().removeClass("game_Active");
    if(1 == _chongisF[_id]){return;}
    _chongisF[_id]=1;
    PerArr[3]=_id;
    AddCWFu();
    $(".p4-shen").show();
});
// 选择道具
$(".p4-daoju").on("click", ".game-li", function () {
    var _id = $(this).attr("data-id");
    $(this).addClass("game_Active").siblings().removeClass("game_Active");
    if(1 == _daoisF[_id]){return;}
    _daoisF[_id]=1;
    
    PerArr[4]=_id;
    AddDaoJu();
    $(".p4-shen").show();
});
//文字
$(".p4-wenzi").on("click", ".game-li", function () {
    var _id = $(this).attr("data-id");
    $(this).addClass("game_Active").siblings().removeClass("game_Active");
    if(1 == _wenisF[_id]){return;}
    _wenisF[_id]=1;
    PerArr[5]=_id;
    AddWenZi();
    $(".p4-shen").show();
});
var _flag=true;
$('.m-btn').on("click",function () {
   if(true == _flag){
      _flag=false;
      _mbg.pause();
      $('.m-btn').attr("src","<?php echo $cdnUrl; ?>img/m-off.png");
   }else{
      _flag=true;
      _mbg.play();
      $('.m-btn').attr("src","<?php echo $cdnUrl; ?>img/m.png");
   }
});
$(".game-cb").on("click", function () {
   var _id=$(this).attr("data-id");
   $(".game-tb").css({"background":'none'});
   $("#p4-tb"+_id).css({"background":'#5cc4c6'});
   $(".gameicobox, .gamebigbox").hide();
   if(1 == _id){
      $(".p4-zishi").show();
   }
   if(2 == _id){
      $(".p4-yifu").show();
   }
   if(3 == _id){
      $(".p4-congwu").show();
   }
   if(4 == _id){
      $(".p4-daoju").show();
   }
   if(5 == _id){
      $(".p4-wenzi").show();
   }
   console.log(_id);
});

$('.p3-zai, .p3-gong').click(function(){
   _chang=$(this).attr("data-id");
   $(".p3-tu").attr("src","<?php echo $cdnUrl; ?>img/p3-"+_chang+".png");
}); 

$('.p2-next').click(function(){
   $(".p2").fadeOut();
   $(".p3").fadeIn();
   _setYF();
});

$('.p2-back').click(function(){
   $(".p2").fadeOut();
   $(".home").fadeIn();
});
$('.p3-back').click(function(){
   $(".p3").fadeOut();
   $(".p2").fadeIn();
}); 
$('.p4-back').click(function(){
   $(".p4").fadeOut();
   $(".p3").fadeIn();
}); 
$('.p3-next').click(function(){
   AddShpFun(_chang);
   $(".p4-zi1").attr("src","<?php echo $cdnUrl; ?>img/"+_sex+"/zs/"+_chang+"1.png");
   $(".p4-zi2").attr("src","<?php echo $cdnUrl; ?>img/"+_sex+"/zs/"+_chang+"2.png");
   
   if('gong' == _chang){
       _zishi='zhan';
    }else{
      _zishi='tang'; 
    }
    _setYF();
   $(".p3").fadeOut();
   $(".p4").fadeIn();
}); 

$('.p5-back').click(function(){
   $(".p5").fadeOut();
   $(".p4").fadeIn();
}); 

$('.home-btn').click(function(){
   $(".home").fadeOut();
   $(".p2").fadeIn();
}); 
$('.p1-nan, .p1-nv').click(function(){
   _sex=$(this).attr("data-id");
   console.log(_sex);
   $(".p2-tou").attr("src","<?php echo $cdnUrl; ?>img/p2-"+_sex+".png");
   $(".p1").fadeOut();
   $(".p2").fadeIn();
}); 
$('.p2-nan, .p2-nv').click(function(){
   _sex=$(this).attr("data-id");
   $(".p2-tou").attr("src","<?php echo $cdnUrl; ?>img/p2-"+_sex+".png");
   $(".p1").fadeOut();
   $(".p2").fadeIn();
   console.log(_sex);
}); 

$(".gamesmallbox").scroll(function () {
    var divwidth = $(".container").width();//设备真实宽度
    var vv = 750 / divwidth;//宽度比例
    var nScrollWidth = $(this)[0].scrollWidth * vv;//滚动条总宽度
    var ww = nScrollWidth - $(this).width() * vv;//滚动条差
    var Left = $(this).scrollLeft();//当前滚动条的宽度
    var Right = -($(this)[0].scrollLeft * vv - ww);//当前滚动条的宽度
    var _thisClass='.'+$(this).attr("data-id");
    console.log(_thisClass);
    if (Left <= 5) {
        $(".game_arrowL").hide()
    }else {
        $(_thisClass + " .game_arrowL").show()
    }
    if(Right<= 6){
      $(".game_arrowR").hide()
    }else {
      $(_thisClass +" .game_arrowR").show()
    }
});

touch.on('.p4-zishi', 'swipeleft', function (ev) {
   $(".game-tb").css({"background":'none'});
   $("#p4-tb2").css({"background":'#5cc4c6'});
   $(".gameicobox, .gamebigbox").hide();
   $(".p4-yifu").show();
});
touch.on('.p4-yifu', 'swiperight', function (ev) {
   $(".game-tb").css({"background":'none'});
   $("#p4-tb1").css({"background":'#5cc4c6'});
   $(".gameicobox, .gamebigbox").hide();
   $(".p4-zishi").show();
});
touch.on('.p4-yifu', 'swipeleft', function (ev) {
   $(".game-tb").css({"background":'none'});
   $("#p4-tb3").css({"background":'#5cc4c6'});
   $(".gameicobox, .gamebigbox").hide();
   $(".p4-congwu").show();
});

touch.on('.p4-congwu', 'swiperight', function (ev) {
   $(".game-tb").css({"background":'none'});
   $("#p4-tb2").css({"background":'#5cc4c6'});
   $(".gameicobox, .gamebigbox").hide();
   $(".p4-yifu").show();
});
touch.on('.p4-congwu', 'swipeleft', function (ev) {
   $(".game-tb").css({"background":'none'});
   $("#p4-tb4").css({"background":'#5cc4c6'});
   $(".gameicobox, .gamebigbox").hide();
   $(".p4-daoju").show();
});
